<?

if($action != ACTION_SAVE_PLAYER) {
	$p_id_hrac = $_GET['id_hrac'];
	
	if($p_id_hrac != "") {
	  $query = getPlayer($p_id_hrac);
	  $fetch = MySQL_Fetch_Array($query);
	  $p_name = $fetch["JMENO"];
	  $p_surname = $fetch["PRIJMENI"];
	  $p_post_id = getPostId($p_id_hrac);
	  $p_birthday = $fetch["NAROZEN"];
	  $p_nameday = $fetch["SVATEK"];
	  $p_hosting = $fetch["HOSTOVANI"];
	  $p_active = $fetch["AKTIVNI"];
	  $p_photo = $fetch["FOTO"];
	} else {
	  $p_name = "";
	  $p_surname = "";
	  $p_post_id = 1;
	  $p_birthday = "";
	  $p_nameday = "";
	  $p_hosting = "";
	  $p_active = 1;
	  $p_photo = "";
	}
}

if ($handle = opendir('./img/hraci')) {
  while ($file = readdir($handle)){
      $polozky[count($polozky)] = $file;
  }
  closedir($handle);
  sort($polozky);
}

reset($polozky);

$pripony = array ("bmp", "jpg", "png", "gif");
?>

<script language="JavaScript" type="text/javascript" src="./js/calendar.js">
</script>

<form action="<? echo redirect_str(PAGE_ADMIN_PLAYER).action(ACTION_SAVE_PLAYER); ?>" method="post">
  
  <input type="hidden" name="p_id_hrac" value="<? echo $p_id_hrac;?>">
  
  <fieldset>
    <legend><? echo ($p_id_hrac!=""?"úprava hráče":"nový hráč"); ?></legend>
    
    <table class="panel-70">
      <tr>
        <td class="righted">jméno <span class="star">*</span></td>
        <td><input class='text px170' type='text' name="p_name" value="<? echo $p_name;?>"></td>
      </tr>
      
      <tr>
        <td class="righted">příjmení <span class="star">*</span></td>
        <td><input class='text px170' type='text' name="p_surname" value="<? echo $p_surname;?>"></td>
      </tr>
      
      <tr>
        <td class="righted">post</td>
        <td>
          <select class='text' name='p_post_id' size=1>
          <?
          $query = getPosts();
          while($fetch = mysql_fetch_array($query)){
                $id = $fetch["id_post"];
                $title = $fetch["nazev"]; 
                if($id == $p_post_id) echo "<option value='$id' selected>$title</option>";
                else echo "<option value='$id'>$title</option>";
          }
          ?>
          </select>
        </td>
      </tr>
      
      <tr>
        <td class="righted">datum narození</td>
        <td>
          <input class='text px70' type='text' name='p_birthday' value="<? echo $p_birthday;?>">
          <img class="icon-btn" onClick="ShowCalendar('formAdminNovyHrac', 'p_birthday', false)" src="./img/icons/calendar.gif">
        </td>
      </tr>
      
      <tr>
        <td class="righted">datum svátku</td>
        <td>
          <input class='text px70' type='text' name='p_nameday' value="<? echo $p_nameday;?>">
          <img class="icon-btn" onClick="ShowCalendar('formAdminNovyHrac', 'p_nameday', false)" src="./img/icons/calendar.gif">
        </td>
      </tr>
      
      <tr>
        <td class="righted">hostování</td>
        <td><input class='text px170' type='text' name='p_hosting' value="<? echo $p_hosting;?>"></td>
      </tr>
      
      <tr>
        <td class="righted">aktivní</td>
        <td><input type="checkbox" name="p_active" <? echo ($p_active == 1?"checked":""); ?>></td>
      </tr>
      
      <tr>
        <td class="righted">foto</td>
        <td>
          <select class='text' name='p_photo' size=1>
            <option value="">není</option>
            <?
            while (list($key, $val) = each($polozky)) {
              $str = explode (".", $val);
              if ($val != "." && $val != ".." && in_array($str[1], $pripony)) {
                if (!is_dir($val)) {
                    if($val == $p_photo)  echo "<option value='$val' selected>$val</option>";
                    else echo "<option value='$val'>$val</option>";
                }
               }
            }
            ?>
          </select>
        </td>
      </tr>
      
      <tr>
        <td colspan="2">
        <div class="center">
        	<input class="button" onmouseover="this.className='button_hover'" 
       			onmouseout="this.className='button'" type="submit" value="ULOŽIT">
       		<a class="button preloader" href="<? echo redirect_str(PAGE_ADMIN_PLAYERS); ?>">ZRUŠIT</a>
        </div>
        </td>
      </tr>
    </table>
  </fieldset>
</form>
